const video = require('./../server/videos');
let videoServer = new video();

function videosServer() {
    let result = {};
    this.getAll = (req,res) => {
        videoServer.getAll(rows => {
            if (rows){
                result.code=1;
                result.data = rows;
                res.write(JSON.stringify(result));
                res.end();
            }
        })
    }
    this.insertInto = (req,res) => {
        videoServer.add(req.body,rows => {
            if (rows){
                result.code=1;
                result.msg = '添加成功';
            } else{
                result.code=0;
                result.msg = '添加失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.del = (req,res) => {
        videoServer.delVideo(req.body.id,rows => {
            if (rows){
                result.code=1;
                result.msg = '删除成功';
            } else{
                result.code=0;
                result.msg = '删除失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.delAll = (req,res) => {
        videoServer.delAllVideo(req.body,rows => {
            if (rows){
                result.code=1;
                result.msg = '批量删除成功';
            } else{
                result.code=0;
                result.msg = '批量删除失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.search = (req,res) => {
        videoServer.search(req.body, rows => {
            if (rows){
                result.code=1;
                result.data = rows;
            } else{
                result.code=0;
                result.msg = '查询失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
}
module.exports = videosServer;
